// pages/client/client.js
let conf = require('../../app.config').app
const systemInfo = wx.getSystemInfoSync();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bg_height:0,
    store_id:0,
    list_data:[],
    type:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let t = this;
    var w = systemInfo.windowWidth;
    var h = systemInfo.windowHeight;
    t.setData({
      bg_height:(750 / 750) * w,
    });

    if(options.store_id){
      t.setData({
        type:options.type,
        store_id:options.store_id,
      });

    }

  },
  cli_address(){
    wx.navigateTo({
      url: '../address/address',
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let t = this;
    t.get_list();
  },
  cli_remove(e){
    let t = this;
    let {
      id
    } = e.currentTarget.dataset;
    wx.showModal({
      title: '提示',
      content: '是否确认删除',
      showCancel: true,
      success:function(res){
        if(res.confirm == true){
          t.api.interface.deleteCustomerAddress(id).then(res => {
            if(res.data.code == 200){
              t.get_list();
            }
          });
        }
      }
    });
  },
  cli_update(e){
    let t = this;
    let {
      id
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '../address/address?id='+id,
    });
  },
  cli_update_default(e){
    let t = this;
    console.log(e);
    let {
      id,isdefault
    } = e.currentTarget.dataset;
    if(isdefault == 0){
      wx.showModal({
        title: '提示',
        content: '是否当天地址改成默认地址？',
        showCancel: true,
        success:function(res){
          if(res.confirm == true){
            t.api.interface.updateCustomerAddressDefault(id).then(res => {
              if(res.data.code == 200){
                t.get_list();
              }

            });
          }
        }
      });
    }


  },
  get_list(){
    let t = this;
    this.api.interface.getCustomerAddressList().then(res => {
      if(res.data.code == 200){
        t.setData({
          list_data: res.data.data
        })
      }

    });
  },
  cli_select_address(e){
    let t = this;
    if(t.data.store_id == 0){
      return false;
    }
    let {
      id
    } = e.currentTarget.dataset;
    if(t.data.type == 1){
      wx.navigateTo({
        url: '../store/store?id='+t.data.store_id+'&address_id='+id
      });
    }else{
      wx.navigateTo({
        url: '../storeDetail/storeDetail?id='+t.data.store_id+'&address_id='+id
      });
    }
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})